<template>
  <div style="margin-left: auto">
    <p>采购发票</p>
  </div>
  <div style="right: auto">
    <span style="float: right;">
      <el-button type="primary" @click="addPurchaseInvoice">保存</el-button>
      <el-button type="Default" @click="">取消</el-button>
      <el-button style="background-color: aquamarine;border-color: aquamarine;color: white;"   :disabled="!isAddSuccess" @click="Examineandapprove">审核</el-button>
      <el-button type="info" @click="">反审核</el-button>
    </span>
  </div>
  <hr />
  <el-scrollbar style="height: 320px; color: dimgray">
    <div class="scrollbar-flex-content">
      <p class="scrollbar-demo-item">
        <el-form :inline="true" :model="form" class="demo-form-inline">
          <el-form-item label="单据编码：" style="width: 308px">
            <el-input v-model="form.documentNo"  :disabled="true" />
          </el-form-item>
          <el-form-item label="单据日期" style="width: 308px">
            <el-date-picker
              v-model="form.documentDate"
              type="date"
              placeholder="Pick a date"
              style="width: 100%"
            />
          </el-form-item>
          <el-form-item label="单据状态" style="width: 308px">
            <input v-model="form.documentStatus" :disabled="true" />
          </el-form-item>
          <el-form-item label="业务状态" style="width: 308px">
            <el-select v-model="form.businessStatusId" placeholder="请选择"   clearable>
              <el-option label="正常" value="1" />
              <el-option label="挂起" value="2" />
              <el-option label="手工关闭" value="3" />
              <el-option label="系统关闭" value="4" />
            </el-select>
          </el-form-item>
        </el-form>

        <el-form :inline="true" :model="form" class="demo-form-inline">
          <el-form-item label="业务类型" style="width: 308px">
            <el-select v-model="form.businessType" placeholder="请选择" clearable>
              <el-option label="零部件发票" value="1" />
              <el-option label="原材料发票" value="2" />
              <el-option label="五金发票" value="3" />
            </el-select>
          </el-form-item>
          <el-form-item label="操作员" style="width: 308px">
            <el-input v-model="form.operator"  :disabled="true" />
          </el-form-item>
          <el-form-item label="审核员" style="width: 308px">
            <el-input v-model="form.auditors"  :disabled="true" />
          </el-form-item>
          <el-form-item label="审核日期" style="width: 308px">
            <el-date-picker
              type="date"
              placeholder="Pick a date"
              style="width: 100%"
              :disabled="true"
            />
          </el-form-item>
        </el-form>

        <el-form :inline="true" style="margin-top: 50px;" :model="form" class="demo-form-inline">
          <el-form-item label="供应商" style="width: 308px">
            <el-input v-model="form.vendor" />
            <el-link type="primary" @click="dialogTableVisibleGYS = true"
            >选择</el-link>
          </el-form-item>
          <div>
            <el-dialog
            v-model="dialogTableVisibleGYS"
            title="选择物料"
            width="900"
            style="height: 600px">
            <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="供应商名称">
            <el-input v-model="formInline.supplierName" placeholder="请输入供应商名称" clearable />
            </el-form-item>
            <el-form-item label="业务联系人">
            <el-input v-model="formInline.businessContact" placeholder="请输入业务联系人" clearable />
            </el-form-item>
            <el-form-item label="供应料品">
            <el-select v-model="formInline.materialTypeName" placeholder="请选择" clearable style="width: 150px;">
                <el-option v-for="item in material" :key="item.materialTypeId" :label="item.materialTypeName"
                    :value="item.materialTypeId" />
            </el-select>
            </el-form-item>


            <el-form-item>
              <el-button type="primary" @click="GetSuppliers()">搜索</el-button>
            </el-form-item>


            </el-form>
            <el-button type="primary" :icon="List" @click="GetSuppliers1()">查询所有</el-button>
    


            <el-empty description="暂无数据" v-show="suppliers.length == 0" />
            <el-table :data="suppliers" stripe style="width: 100%" v-show="suppliers.length != 0">
                <el-table-column prop="supplierId" label="序号" />
                <el-table-column prop="supplierName" label="供应商名称" />
                <el-table-column prop="supplierAbbreviation" label="简称" />
                <el-table-column prop="companyAddress" label="公司地址" />
                <el-table-column prop="phone" label="电话" />
                <el-table-column prop="businessContact" label="业务联系人" />
                <el-table-column prop="materialTypeName" label="供应料品" />
                <el-table-column label="操作">
                    <template #default="scope">
                        <el-link type="primary" @click="xzgys(scope.row)">选择</el-link> &nbsp;
                    </template>
                </el-table-column>
            </el-table>
         <div>
        <tr>
            <td>
                <el-pagination v-model:current-page="formInline.pageIndex" v-model:page-size="formInline.pageSize"
                    :page-sizes="[10, 20, 30, 40, 50]" :background="true" layout="total, slot, prev, pager, next"
                    :total="formInline.totalCount" @size-change="handleSizeChange"
                    @current-change="handleCurrentChange">
                </el-pagination>
            </td>
            <td>
                <el-pagination v-model:current-page="formInline.pageIndex" v-model:page-size="formInline.pageSize"
                    :page-sizes="[10, 20, 30, 40, 50]" :background="true" layout="slot, sizes, jumper"
                    :total="formInline.totalCount" @size-change="handleSizeChange"
                    @current-change="handleCurrentChange">
                </el-pagination>
            </td>
        </tr>
    </div>
            </el-dialog>
          </div>

          <el-form-item label="税号" style="width: 308px">
            <el-input v-model="form.taxNo" />
          </el-form-item>
          <el-form-item label="发票类型" style="width: 308px">
            <el-cascader v-model="form.invoiceTypeId"
              :options="invoiceTypeData"
              @change="handleChange"  clearable />
          </el-form-item>
          <el-form-item label="发票代码" style="width: 308px">
            <el-input v-model="form.invoiceCode" />
          </el-form-item>
          <el-form-item label="发票号码" style="width: 308px">
            <el-input v-model="form.invoiceNumber" />
          </el-form-item>
        </el-form>

        <el-form :inline="true" style="margin-top: 50px;" :model="form" class="demo-form-inline">
          <el-form-item label="开票日期" style="width: 308px">
            <el-date-picker
              v-model="form.billingDate"
              type="date"
              placeholder="Pick a date"
              style="width: 100%"
            />
          </el-form-item>

          <el-form-item label="红字篮字" style="width: 308px">
            <el-select
              v-model="form.redBasketLetter"
              placeholder="Select"
              size="large"
              style="width: 240px"
            >
              <el-option
                label="蓝字"
                value="蓝字"
              />
              <el-option
                label="红字"
                value="红字"
              />
            </el-select>
          </el-form-item>
   
          <el-form-item label="发票金额" style="width: 308px">
            <el-input v-model="form.invoiceAmount" />
          </el-form-item>

          <el-form-item label="税额" style="width: 308px">
            <el-input v-model="form.tax" />
          </el-form-item>
          <el-form-item label="价税合计" style="width: 308px">
            <el-input v-model="form.priceTaxTotal" />
          </el-form-item>
        </el-form>

        <el-form style="margin-top: 50px;" :inline="true" :model="form" class="demo-form-inline">
          <div>
             <el-dialog v-model="dialogFormVisiblePDF" title="上传PDF" width="500">
      <el-upload
        class="upload-demo"
        drag
        action="http://localhost:5020/api/SalesManagementWrite/UploadFile"
        :before-upload="beforeUpload1"
        :on-success="handleSuccess1"
        multiple
      >
        <el-icon class="el-icon--upload"><upload-filled /></el-icon>
        <div class="el-upload__text">Drop file here or <em>click to upload</em></div>
        <template #tip>
          <div class="el-upload__tip">PDF files with a size less than 500kb</div>
        </template>
      </el-upload>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogFormVisiblePDF = false">取 消</el-button>
          <el-button type="primary" @click="handleConfirm1">确 定</el-button>
        </span>
      </template>
    </el-dialog>
          </div>
          <el-form-item label="发票上传" style="width: 308px">
            <el-input v-model="form.onInvoice" style="width: 149PX;" />
            <el-link type="primary" @click="dialogFormVisiblePDF = true">上传</el-link>
          </el-form-item>
          <el-form-item label="XML格式" style="width: 308px">
            <el-input v-model="form.xmlFormat" style="width: 149PX;" />
            <el-link type="primary" @click="dialogFormVisibleXML = true"
            >上传</el-link>
          </el-form-item>
          <div>

            
<el-dialog v-model="dialogFormVisibleXML" title="上传XML" width="500">
  <el-upload
    class="upload-demo"
    drag
    action="http://localhost:5020/api/SalesManagementWrite/UploadFile"
    :before-upload="beforeUpload"
    :on-success="handleSuccess"
    multiple
  >
    <el-icon class="el-icon--upload"><upload-filled /></el-icon>
    <div class="el-upload__text">Drop file here or <em>click to upload</em></div>
    <template #tip>
      <div class="el-upload__tip">jpg/png files with a size less than 500kb</div>
    </template>
  </el-upload>
  <template #footer>
    <span class="dialog-footer">
      <el-button @click="dialogFormVisibleXML = false">取 消</el-button>
      <el-button type="primary" @click="handleConfirm">确 定</el-button>
    </span>
  </template>
</el-dialog>

          </div>
          <el-form-item label="OFD格式" style="width: 308px">
            <el-input v-model="form.ofpFormat" style="width: 149PX;" />
            <el-link type="primary" @click="dialogFormVisibleOFD = true"
            >上传</el-link>
          </el-form-item>
          <div>
    <el-dialog v-model="dialogFormVisibleOFD" title="上传OFD" width="500">
      <el-upload
        class="upload-demo"
        drag
        action="http://localhost:5020/api/SalesManagementWrite/UploadFile"
        :before-upload="beforeUpload2"
        :on-success="handleSuccess2"
        multiple
      >
        <el-icon class="el-icon--upload"><upload-filled /></el-icon>
        <div class="el-upload__text">Drop file here or <em>click to upload</em></div>
        <template #tip>
          <div class="el-upload__tip">OFD files with a size less than 500kb</div>
        </template>
      </el-upload>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogFormVisibleOFD = false">取 消</el-button>
          <el-button type="primary" @click="handleConfirm2">确 定</el-button>
        </span>
      </template>
    </el-dialog>
          </div>
          <el-form-item label="发票状态" style="width: 308px">
            <el-select :disabled="true" v-model="form.invoiceStatus" style="width: 149PX;" >
              <el-option label="录入" value="录入"  />
            </el-select>
          </el-form-item>
          <el-form-item label="备注信息" style="width: 308px">
            <el-input v-model="form.remarkInfo" style="width: 149PX;" type="textarea" />
          </el-form-item>
        </el-form>
      </p>
    </div>
  </el-scrollbar>
  <div style="float: right;">
    <el-button type="warning" @click="">¼ 引入</el-button>
    <el-button type="primary" @click="addMaterial">新增物料</el-button>

  </div>
 
  <table style="border-collapse: collapse">
    <tr>
      <td style="width: 90px;">序号</td>
      <td style="width: 90px;">采购订单号</td>
      <td style="width: 90px;">仓库</td>
      <td style="width: 90px;">入库单号</td>
      <td style="width: 90px;">物料编码</td>
      <td style="width: 90px;">物料名称</td>
      <td style="width: 90px;">型号规格</td>
      <td style="width: 90px;">主计量</td>
      <td style="width: 90px;">数量</td>
      <td style="width: 90px;">单价</td>
      <td style="width: 90px;">金额</td>
      <td style="width: 90px;">税率</td>
      <td style="width: 90px;">税额</td>
      <td style="width: 90px;">操作</td>
    </tr>
    <tr v-for="(ruleForm, index) in loge.healthArray">
      <td style="width: 90px;">
      {{ruleForm.materialId}}   <!-- 序号 -->
      </td>
      <td style="width: 90px;">
        <span v-if="ruleForm.logisticsCode!=''">{{ ruleForm.purchaseON  }}</span>
        <span v-else></span>
        <!--purchaseON 采购订单号--> 
      </td>
      <td style="width: 90px;">
        <span v-if="ruleForm.logisticsCode!=''">{{ ruleForm.warehouse  }}</span>
        <span v-else></span>
      </td>
      <td style="width: 90px;" >
        <span v-if="ruleForm.logisticsCode!=''">{{  ruleForm.inventoryRN  }}</span>
        <span v-else></span>
      </td>
      <td style="width: 90px;">
        {{ ruleForm.logisticsCode }} <!--logisticsCode 物流编码-->
        <el-link type="primary" @click="xuanz(index)">选择</el-link>
        <div>
          <el-dialog
            v-model="dialogTableVisibleWl"
            title="选择物料"
            width="900"
            style="height: 600px"
          >
            <div class="common-layout" style="width: 165px; float: left">
              <el-container>
                <el-aside width="165px" style="margin-left: 10px">
                  <el-tree
                    ref="treeRef"
                    class="filter-tree"
                    :data="data"
                    :props="defaultProps"
                    style="
                      width: 165px;
                      border: 0px solid #ccc;
                      float: left;
                      height: 500px;
                    "
                    default-expand-all
                    :expand-on-click-node="false"
                    :filter-node-method="filterNode"
                    @node-click="handleNodeClick"
                  />
                </el-aside>
                <el-main> </el-main>
              </el-container>
            </div>
            <div class="common-layout" style="float: right; top: 12px">
              <el-form :inline="true" :model="page" class="demo-form-inline">
                <el-form-item label="物料编码">
                  <el-input v-model="Materials.itemBianma" />
                </el-form-item>
                <el-form-item label="物料名称">
                  <el-input v-model="Materials.itemName" />
                </el-form-item>
                <el-button type="primary" @click="SearchMaterialsShow">搜索</el-button>
              </el-form>
              <el-table :data="MaterialsShowlist" style="height: 500px">
                <el-table-column property="itemBianma" label="物料编码" width="150" />
                <el-table-column property="itemName" label="物料名称" width="200" />
                <el-table-column property="modelspecification" label="型号规格" />
                <el-table-column property="measureId" label="主计量" />
                <el-table-column label="操作">
                  <template #default="scope">
                    <el-button type="primary" @click="Selectnumber(scope.row.itemBianma, scope.row.itemName, scope.row.modelspecification,scope.row.measureId,index1)">选择</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-dialog>
        </div>
      </td>
      <td style="width: 90px;">{{ ruleForm.nameOfLogistics  }}</td><!--nameOfLogistics 物料名称 -->
      <td style="width: 90px;">{{ruleForm.modelSpecification }}</td><!--modelSpecification 型号规格 -->
      <td style="width: 90px;">{{ ruleForm.mainMetering }}</td><!--mainMetering 主计量 -->
      <td style="width: 90px;">
        <el-input v-model="ruleForm.num"  placeholder="请输入数量" style="width: 100px" ></el-input>
        </td style="width: 90px;"><!--num 数量 -->
      <td style="width: 90px;">
        <el-input v-model="ruleForm.price" @blur="jisuan(index)" placeholder="请输入单价" style="width: 100px" ></el-input></td>
      <td style="width: 90px;"><el-input v-model="ruleForm.amount" @blur="jisuan(index)" style="width: 100px" ></el-input></td>
      <td style="width: 90px;"><el-input v-model="ruleForm.taxRate" @blur="jisuan(index)" style="width: 100px" ></el-input></td>
      <td style="width: 90px;"><el-input v-model="ruleForm.amountOfTax" @blur="jisuan(index)" style="width: 100px" ></el-input></td><!-- 税额 -->
      <td style="width: 90px;">
        <el-button type="danger" link @click="del">删除</el-button>
      </td>
    </tr>
  </table>
</template>

<script setup lang="ts">
import { reactive, ref, onMounted, computed } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';
import { useRoute } from 'vue-router';
import Cookie from 'cookies-ts';
const cookie = new Cookie()
import axios from 'axios';
import { number } from 'echarts';
import { Plus, Download, Upload, List } from '@element-plus/icons-vue'
const dialogFormVisiblePDF: any = ref(false);
const dialogTableVisible: any = ref(false);
const dialogFormVisibleXML: any = ref(false);
const dialogFormVisibleOFD: any = ref(false);
const dialogTableVisibleWl:any =ref(false)
const dialogTableVisibleGYS:any =ref(false)
const apiurls = import.meta.env.VITE_APP_API_URL_BasicInformationCommon;//5176
const bpiurls = import.meta.env.VITE_APP_API_URL_BasicInformationWrite;//5013
const cpiurls = import.meta.env.VITE_APP_API_URL_RBACCommon;//5214
const dpiurls = import.meta.env.VITE_APP_API_URL_RBACWrite;//5268
const epiurls = import.meta.env.VITE_APP_API_URL_SalesManagementCommon;//5227
const fpiurls = import.meta.env.VITE_APP_API_URL_SalesManagementWrite;//5020
const formLabelWidth = '140px';
const isAddSuccess =ref(false)//初始状态为未新增成功
onMounted(() => {
  GetBang();
  SearchMaterialsShow()
  getMaterial()
  GetSuppliers()
  GetSuppliers1()
  getinvoiceType()
});

const form = reactive({
  serialNumber:'',
  documentNo: '',
  businessType: 0,
  vendor: '',
  billingDate: '',
  onInvoice: '',
  documentDate: '',
  operator: 'liy',
  taxNo: '',
  redBasketLetter: '',
  xmlFormat: '',
  documentStatus: '开立',
  auditors: '',
  invoiceTypeId: '',
  invoiceAmount: 0,
  ofpFormat: '',
  businessStatusId:'',
  dateOfReview: '',
  invoiceCode: '',
  tax: 0,
  invoiceStatus: '录入',
  invoiceNumber: '',
  priceTaxTotal: '',
  remarkInfo: '',
});

const numbers = ref(1)
const loge = reactive({
  healthArray:<any>[
     reactive({
      materialId:numbers.value,
      purchaseON: '手工单据',
      warehouse: '手工单据',
      inventoryRN: '手工单据',
      logisticsCode: '',
      nameOfLogistics: '',
      modelSpecification: '',
      mainMetering: 0,
      num: 0,
      price: 0,
      amount: 0,
      taxRate: 0,
      amountOfTax: 0,
      serialNumber: '',
     })
  ]
  
});
//新增行
const addMaterial=()=>{
  loge.healthArray.push(reactive({
      materialId:loge.healthArray.length + numbers.value,
      purchaseON: '手工单据',
      warehouse: '手工单据',
      inventoryRN: '手工单据',
      logisticsCode: '',
      nameOfLogistics: '',
      modelSpecification: '',
      mainMetering: 0,
      num: 0,
      price: 0,
      amount: 0,
      taxRate: 0,
      amountOfTax: 0,
      serialNumber:'',
  }))
}
//删除行
const del = () => {
    loge.healthArray.splice(loge.healthArray.length - 1, 1)
    ElMessage.warning({
        message: '删除成功',
    })
}
const jisuan=(index:number)=>{
  var price = loge.healthArray[index].price
  var num = loge.healthArray[index].num
  loge.healthArray[index].amount=(price*num).toFixed(2)
  // loge.healthArray[index].amount
  var amount = loge.healthArray[index].amount
  var taxRate= loge.healthArray[index].taxRate=0.13
  loge.healthArray[index].amountOfTax=(amount*taxRate).toFixed(2)
}
//发票类型
let invoiceTypeIds:any=[];
const handleChange = (val:any)=>{
  invoiceTypeIds=val.toString();
  console.log(invoiceTypeIds)
}
const invoiceTypeData:any = ref([]);
const getinvoiceType=()=>{
  axios.get(epiurls+'/api/SalesOrder/InvoiceTypeQuery').then(res=>{
    console.log(res);
    invoiceTypeData.value =res.data.data
    console.log(invoiceTypeData.value,123456);
    
  }).catch(err=>{
    console.log(err);
    
  })
}
//选择物料
const uptform =reactive({
  materialTypeName:'',
  pId:0,
})
const filterNode = (value: string, data: any) => {
    if (!value) return true;
    return data.label.includes(value);
};
//树形级联
const defaultProps = {
    children: 'children',
    label: 'label',
}
var data = ref([])
function GetBang() {
    axios({
        url: apiurls+'/api/Materials/GetmaterialTree',
        method: 'get'
    })
        .then((res) => {
            data.value = res.data.data
        })
}

const handleNodeClick = (data: any) => {

uptform.materialTypeName = data.label
uptform.pId = data.value
console.log(uptform.pId)
}
const page = reactive({
    customerName: "",
    businessContacts: "",
    PageIndex: 1,
    PageSize: 100,
    totalCount: 0,
    pageCount: 0,
})
const Materials = reactive({
    itemBianma: "",
    itemName: ""
})

const MaterialsShowlist = ref([])
const SearchMaterialsShow = () => {
    axios.get(apiurls+'/api/Materials/MaterialesSearch', {
        params: {
            materialTypeId: uptform.pId,
            itemBianma: Materials.itemBianma,
            itemName: Materials.itemName
        }
    }).then((res) => {
        MaterialsShowlist.value = res.data.data2
        console.log(MaterialsShowlist.value);
    })
}
const index1 = ref(0)
const xuanz = (index: any) => {
  dialogTableVisibleWl.value=true
  index1.value = index
}

const Selectnumber = (itemBianma: any, materialName: any, typeSpecification: any,measureId:any, index: any) => {
    console.log(index)
    localStorage.setItem('itemBianma', itemBianma)
    localStorage.setItem('itemName', materialName)
    localStorage.setItem('modelspecification', typeSpecification)
    localStorage.setItem('measureId', measureId)
    if (localStorage.getItem('itemBianma') != null || localStorage.getItem('itemName') != null || localStorage.getItem('modelspecification') != null || localStorage.getItem('measureId') != null) {
      loge.healthArray[index].logisticsCode = localStorage.getItem('itemBianma') as string
      loge.healthArray[index].nameOfLogistics = localStorage.getItem('itemName') as string
      loge.healthArray[index].modelSpecification = localStorage.getItem('modelspecification') as string
      loge.healthArray[index].mainMetering = localStorage.getItem('measureId') as string
    }
    console.log(loge.healthArray[index])
    dialogTableVisibleWl.value = false
}

const addPurchaseInvoice=()=>{
  let request: any = ref([{}]);
  request= loge.healthArray;
  console.log(111,loge,loge.healthArray);
  const datas={
  serialNumber:'',
  documentNo:form.documentNo ,
  businessType:form.businessType,
  vendor:form.vendor,
  billingDate:form.billingDate,
  onInvoice: form.onInvoice,
  documentDate: form.documentDate,
  operator: form.operator,
  taxNo: form.taxNo,
  redBasketLetter: form.redBasketLetter,
  xmlFormat: form.xmlFormat,
  documentStatus: form.documentStatus,
  auditors: form.auditors,
  invoiceTypeId:invoiceTypeIds,
  invoiceAmount:form.invoiceAmount,
  ofpFormat: form.ofpFormat,
  businessStatusId:form.businessStatusId,
  invoiceCode: form.invoiceCode,
  tax:form.tax,
  invoiceStatus: form.invoiceStatus,
  invoiceNumber: form.invoiceNumber,
  priceTaxTotal: form.priceTaxTotal,
  remarkInfo: form.remarkInfo,
  purchaseInvoiceSubtables:request
}
  console.log(datas,66666);
  axios.post(fpiurls+'/api/SalesManagementWrite/PurchaseInvoiceCreate',datas).then(res => {
       if(res.data.code==0){
        ElMessage.success(res.data.msg)
        isAddSuccess.value = true;  // 新增成功审批启用
       }
       else{
        ElMessage.error(res.data.msg)
       }
    })
} 
//上传图片
const beforeUpload = (file:any) => {
  const isXML = file.type === 'text/xml';
  if (!isXML) {
    ElMessage.error('请上传XML格式的文件');
  }
  return isXML;
};

const handleSuccess = (response:any, file:any, fileList:any) => {
  form.xmlFormat = fileList[0].response; // 假设服务器返回文件路径
  console.log(form.xmlFormat,111);
  
};

const handleConfirm = () => {
  dialogFormVisibleXML.value = false;
  // 这里可以添加其他逻辑，比如提交表单等
};






const beforeUpload1 = (file:any) => {
  const isPDF = file.type === 'application/pdf';
  if (!isPDF) {
    ElMessage.error('请上传PDF格式的文件');
  }
  return isPDF;
};

const handleSuccess1 = (response:any, file:any, fileList:any) => {
  form.onInvoice = fileList[0].response; // 假设服务器返回文件路径
};

const handleConfirm1 = () => {
  dialogFormVisiblePDF.value = false;
  // 这里可以添加其他逻辑，比如提交表单等
};



const beforeUpload2 = (file:any) => {
  const isOFD = file.type === 'application/ofd';
  if (!isOFD) {
    ElMessage.error('请上传OFD格式的文件');
  }
  return isOFD;
};

const handleSuccess2 = (response:any, file:any, fileList:any) => {
  form.ofpFormat = fileList[0].response; // 假设服务器返回文件路径
};

const handleConfirm2 = () => {
  dialogFormVisibleOFD.value = false;
  // 这里可以添加其他逻辑，比如提交表单等
};
//供应商
const formInline = reactive({
    supplierName: '',
    businessContact: '',
    materialTypeName: '',
    pageIndex: 1,
    pageSize: 10,
    pageCount: 0,
    totalCount: 0,

})

//供应商列表
const suppliers: any = ref([]);
const GetSuppliers = () => {
    axios
        .get(
          apiurls+'/api/Suppliers/SuppliersList',
            {
                params: {
                    supplierName: formInline.supplierName,
                    businessContact: formInline.businessContact,
                    materialTypeName: formInline.materialTypeName || 0,
                    pageIndex: formInline.pageIndex,
                    pageSize: formInline.pageSize,
                }
            }
        )
        .then((res) => {
            console.log(res.data.data);
            suppliers.value = res.data.data;
            formInline.pageCount = res.data.pageCount;
            formInline.totalCount = res.data.totalCount;
        })
        .catch((err) => {
            console.log(err);
        });
};

const GetSuppliers1 = () => {
    axios
        .get(
            apiurls+'/api/Suppliers/SuppliersList',
            {
                params: {
                    supplierName: '',
                    businessContact: '',
                    materialTypeName: 0,
                    pageIndex: formInline.pageIndex,
                    pageSize: formInline.pageSize,
                }
            }
        )
        .then((res) => {
            console.log(res.data.data);
            suppliers.value = res.data.data;
            formInline.pageCount = res.data.pageCount;
            formInline.totalCount = res.data.totalCount;
        })
        .catch((err) => {
            console.log(err);
        });
};

//分页
const handleSizeChange = (val: number) => {
    formInline.pageSize = val
    GetSuppliers()
}
const handleCurrentChange = (val: number) => {
    formInline.pageIndex = val
    GetSuppliers()
}
//物料下拉框
const material: any = ref([]);
const getMaterial = () => {
    axios
        .get(apiurls+'/api/Suppliers/MaterialList')
        .then((res) => {
            console.log(res.data.data);
            material.value = res.data.data;
        })
        .catch((err) => {
            console.log(err);
        });
};
//选择供应商
const xzgys=(row:any)=>{
    form.vendor=row.supplierName
    dialogTableVisibleGYS.value=false
}


 var employeeName =cookie.get('employeeName')
 console.log(employeeName,123456);
 
//审核参数
const Examineand = reactive({
  workid:2,
  username:employeeName,
  uSerid:1,
  workType:1,
  gnumid:'CGFP20240106'
})




//审批流程
const Examineandapprove=()=>{
  axios.post('http://localhost:5020/api/SalesManagementWrite/ProcessFlowEngineHandle',Examineand).then(res=>{
    if(res.data.code==1)
    {
      ElMessage.success(res.data.msg)
      if(res.data.msg=='审批成功')
      {
        form.documentStatus='审批中'
      }
      else if(res.data.msg=='撤销成功')
      {
        form.documentStatus='开立'
      }

    }
  }).then(err=>{

  })
}
</script>

<style scoped>
.scrollbar-flex-content {
  display: flex;
}

.scrollbar-demo-item {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1800px;
  height: 300px;
  margin: 10px;
  text-align: center;
  border-radius: 4px;
}
</style>
<style scoped>
.demo-pagination-block + .demo-pagination-block {
  margin-top: 10px;
}

.demo-pagination-block .demonstration {
  margin-bottom: 16px;
}

/* 设置第一行的 td 顶部边框加粗并设置为红色 */
table tr:first-child td {
  border-top: 1px solid #ccc;
  /* 设置顶部边框为3px宽度的红色 */
  padding: 10px;
  text-align: center;
}

/* 设置 td 的样式 */

table td {
  padding: 10px;
  border: 1px solid #ccc;
  text-align: center;
  font-size: 14px;
  height: 60px;
  width: 150px;
  white-space: nowrap;
  /* 防止内容换行 */
}

/* 可选：为 table 添加样式 */
table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

/*______________________________________________________*/

.table-container {
  max-width: 100%;
  overflow-x: auto;
  /* 启用水平滚动 */
  margin: 20px 0;
  /* 设置容器的外边距 */
}

/* :deep(.el-input__wrapper) {
  box-shadow: none;
  text-align: center;
}

:deep(.el-select__wrapper) {
  box-shadow: none;
}

::v-deep(.center-input .el-input__inner) {
  text-align: center;
} */
</style>

<style scoped>
.upload-demo {
  display: inline-block;
  width: 100%;
}
</style>





